package games.ninJumpDx.ui.actions
{
	import flash.display.Bitmap;
	import flash.utils.getTimer;
	
	import games.ninJumpDx.data.GameData;
	import games.ninJumpDx.data.UIConfig;
	import games.ninJumpDx.tools.Tools;
	
	import utils.Cartoon;
	
	public class Dragon extends Cartoon
	{
		private var m_over:int;
		protected var info:XMLList ;
		public function Dragon(name:String)
		{
			super();
			m_over = 0;
			addChild(Tools.getBitmapByName(name,GFrame.MAIN_UI));
			info = UIConfig.getInfoByName(name);
			x = info.@x;
			trace(info.toXMLString());
			y = UIConfig.getInfoByName(name).@y;
			if(info.hasOwnProperty("@scaleX"))
			{
				trace("*****************",info.hasOwnProperty(scaleX));
				scaleX = info.@scaleX;
			}
			
			
		}
		
		override public function update(t:Object=null):void
		{
			if(!start || pause)return;
			
			if(scaleX > 0)
			{
				if(x < 0 && m_over == 0)
					x += GameData.instance.speed ;
				else
				{
					if(m_over < 20)
					{
						// 吐火球
						m_over ++;
						return;
					}
					x -= GameData.instance.speed ; 
					if(x < -width)
						destroy();
				}
				
			}else
			{
				if(x > UIConfig.getGameWidth() && m_over == 0)
					x -= GameData.instance.speed ;
				else
				{
					if(m_over < 20)
					{
						// 吐火球
						m_over ++;
						return;
					}
					x += GameData.instance.speed ;
					if(x > UIConfig.getGameWidth() + width)
						destroy();
				}
				
			}
			
		}
		
		override public function destroy(e:* = null):void
		{
			super.destroy();
			while(numChildren > 0)
			{
				var mc:Bitmap = Bitmap(removeChildAt(0));
				mc.bitmapData.dispose();
			}
			info = null;
		}
	}
}